﻿@{
    ViewData["Title"] = "销售填写";
}
<form role="form" class="form-horizontal">
    <!--客户信息-->
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">NAME OF SALES REP\销售姓名<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_orderNO">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">
            SALES REP.PHONE\销售电话<em style="color: red;">*</em>
        </label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_BuyWay">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">SALES REP.CODE\销售代号<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-4 control-label" style="color: darkblue;">商品信息，共3条</label>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">MODEL\型号<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">QUANTITY\数量<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">CONTRACT DURATION(RENTAL ONLY)\租赁期限（仅限租赁）<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">REGISTRATION FEE(RENTAL ONLY)\租赁登记费（仅限租赁）<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">MONTHLY RENT(W/O TAX)\每月租赁费<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">SALES PRICE(W/O TAX)\购买价格<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">MONTHLY PAYMENT METHOD(RENTAL ONLY)\每月付款方式<em style="color: red;">*</em>
        </label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name"></label>
        <div class="col-sm-5">
            <button type="button" onclick="Save()" class="btn btn-primary">保存</button>
        </div>
    </div>
</form>

@section Scripts{
    <script type="text/javascript">
        function getQueryString(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            let r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURIComponent(r[2]);
            };
            return null;
        }

        $(function () {
            Initia();
        });

        //初始化数据
        function Initia() {
            $.ajax({
                url: "http://106.15.9.236:40580/api/app/order/draftSellOrder?sellerCode=" + getQueryString("sellerCode"),
                contentType: "application/json-patch+json",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data) {
                        $("#txt_orderNO").val(data.sellerName);
                    }
                },
                error: function () {
                    toastr.error("服务不可用，请联系管理员");
                }
            })
        }

        //保存
        function Save() {
            var orderNo = $("#txt_orderNO").val().trim();
            var buyWay = $("#txt_BuyWay").val().trim();
            var referralNo = $("#txt_ReferralNo").val().trim();
            
            var ParamData = {
                orderNo: orderNo,
                buyWay: buyWay,
                referralNo: referralNo
            };

            $.ajax({
                url: "http://106.15.9.236:40580/api/app/order",
                contentType: "application/json-patch+json",
                type: "POST",
                data: JSON.stringify(ParamData),
                dataType: "json",
                success: function (data) {
                    alert("保存成功！" + data.id);
                    window.location.href = '/home/pay?orderId=' + data.id;
                },
                error: function (data) {
                    alert("保存失败！\r\n" + data.responseJSON.error.message);
                }
            })
        };
        //弹出模态框
        function alterModel(val) {
            $('#myModal').modal('show')
            $("#alterContent").text(val);
        }

        // 测试数据库
        function TestDB() {
            $.ajax({
                url: "/api/app/consulKV/testDB",
                contentType: "application/json-patch+json",
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if (data.result == true) {
                        toastr.success("测试数据库成功！");
                    } else {
                        toastr.error("测试数据库失败，请确认Sql2008是否打了SP3不对");
                    }
                }
            })
        };


        // 获取老POS需要的图片地址
        function GetPOSImageUrl() {
            $.ajax({
                url: "/api/app/consulKV/posimageurl",
                contentType: "application/json-patch+json",
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if (data.BigPicturePath != "") {
                        $("#div_resultCode").attr("style", "display:block;");
                        $("#resultTitle").html("老POS的图片地址：");
                        $("#resultCode").html(data.bigPicturePath + '</br>' + data.smallPicturePath);
                    } else {
                        toastr.error("请配置图片中心域名");
                    }
                }
            })
        };

        // 获取系统地址
        function GetSystemUrl() {
            $.ajax({
                url: "/api/app/consulKV/systemurl",
                contentType: "application/json-patch+json",
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if (data.resultMessage) {
                        $("#div_resultCode").attr("style", "display:block;");
                        $("#resultTitle").html("系统访问地址：");
                        $("#resultCode").html(data.resultMessage);
                    }

                    if (data.result == true) {
                        toastr.success("获取系统地址成功！");
                    }
                }
            })
        };

        // 检查配置参数
        function CheckAppSettings() {
            $.ajax({
                url: "/api/app/consulKV/checkAppSettings",
                contentType: "application/json-patch+json",
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if (data.resultMessage) {
                        $("#div_resultCode").attr("style", "display:block;");
                        $("#resultTitle").html("配置参数检查结果：");
                        $("#resultCode").html(data.resultMessage);
                    }

                    if (data.result == true) {
                        toastr.success("恭喜您，配置都正确的，非常棒！");
                    } else {
                        toastr.error("抱歉，配置有误请修正！");
                    }
                }
            })
        };


    </script>
}
